package vcp.gui.forms;

import java.awt.Color;
import java.util.Observable;
import java.util.Observer;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;

import vcp.gui.components.VCPPanel;
import client.Message;

import com.toedter.calendar.JDateChooser;

import db.parking.beans.Subscriber;
import javax.swing.border.TitledBorder;

/**
 * Regular SubscriptionForm
 *
 */
public class SubscriptionFormRegular extends VCPPanel implements Observer {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	private JTextField textCID; 
	
	
	private JButton btnSusbcribe;
	private JLabel lblCarNumber;
	private JTextField carNo_field;
	private JLabel lblSubscriptionStart;
	private JTextField textField;
	private JDateChooser dateChooserStart;
	private JLabel lblLeaveTime;
	private JLabel cusID_label;
	private JTextField textField_h;
	private JTextField textField_m;
	private JLabel lblLotNumber;
	
	public JTextField getTextField_h() {
		return textField_h;
	}
	public void setTextField_h(JTextField textField_h) {
		this.textField_h = textField_h;
	}
	public JTextField getTextField_m() {
		return textField_m;
	}
	public void setTextField_m(JTextField textField_m) {
		this.textField_m = textField_m;
	}
	public JLabel getLblLotNumber() {
		return lblLotNumber;
	}
	public void setLblLotNumber(JLabel lblLotNumber) {
		this.lblLotNumber = lblLotNumber;
	}
	public JLabel getLblCarNumber() {
		return lblCarNumber;
	}
	public void setLblCarNumber(JLabel lblCarNumber) {
		this.lblCarNumber = lblCarNumber;
	}
	public JTextField getCarNo_field() {
		return carNo_field;
	}
	public void setCarNo_field(JTextField carNo_field) {
		this.carNo_field = carNo_field;
	}
	public JLabel getLblSubscriptionStart() {
		return lblSubscriptionStart;
	}
	public void setLblSubscriptionStart(JLabel lblSubscriptionStart) {
		this.lblSubscriptionStart = lblSubscriptionStart;
	}
	public JTextField getTextField() {
		return textField;
	}
	public void setTextField(JTextField textField) {
		this.textField = textField;
	}
	public JDateChooser getDateChooserStart() {
		return dateChooserStart;
	}
	public void setDateChooserStart(JDateChooser dateChooserStart) {
		this.dateChooserStart = dateChooserStart;
	}
	public JLabel getLblLeaveTime() {
		return lblLeaveTime;
	}
	public void setLblLeaveTime(JLabel lblLeaveTime) {
		this.lblLeaveTime = lblLeaveTime;
	}
	public JLabel getCusID_label() {
		return cusID_label;
	}
	public void setCusID_label(JLabel cusID_label) {
		this.cusID_label = cusID_label;
	}
	/**
	 * Create the panel.
	 */
	public SubscriptionFormRegular() {
		setBorder(new TitledBorder(null, "Subscription", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setBackground(Color.WHITE);
		
		cusID_label = new JLabel("Customer ID ");
		
		textCID = new JTextField();
		textCID.setColumns(10);
		
		btnSusbcribe = new JButton("Subscribe");
		btnSusbcribe.setActionCommand("reg_subscription");
		
		lblCarNumber = new JLabel("Car Number");
		
		carNo_field = new JTextField();
		carNo_field.setColumns(10);
		
		lblSubscriptionStart = new JLabel("Subscription Start");
		
		dateChooserStart = new JDateChooser();
		
		lblLotNumber = new JLabel("Lot Number");
		
		textField = new JTextField();
		textField.setColumns(10);
		
		lblLeaveTime = new JLabel("Leave Time");
		
		textField_h = new JTextField();
		textField_h.setColumns(10);
		
		textField_m = new JTextField();
		textField_m.setColumns(10);
		
		JLabel label = new JLabel(":");
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(lblLotNumber, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblLeaveTime, GroupLayout.PREFERRED_SIZE, 122, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblSubscriptionStart, GroupLayout.PREFERRED_SIZE, 122, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblCarNumber, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)
								.addComponent(cusID_label))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
									.addComponent(dateChooserStart, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
									.addComponent(carNo_field, GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
									.addComponent(textField)
									.addComponent(textCID))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(textField_h, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
									.addGap(10)
									.addComponent(label)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(textField_m, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)))
							.addContainerGap(14, Short.MAX_VALUE))
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(btnSusbcribe)
							.addGap(122))))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(21)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(textCID, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(cusID_label))
					.addGap(15)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(carNo_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblCarNumber))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(dateChooserStart, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblSubscriptionStart))
					.addGap(24)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblLotNumber))
					.addGap(13)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblLeaveTime)
						.addComponent(textField_h, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(label, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField_m, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(12)
					.addComponent(btnSusbcribe)
					.addContainerGap(28, Short.MAX_VALUE))
		);
		setLayout(groupLayout);

	}
	public JTextField getTextCID() {
		return textCID;
	}
	public void setTextCID(JTextField textCID) {
		this.textCID = textCID;
	}
	public JButton getBtnSusbcribe() {
		return btnSusbcribe;
	}
	public void setBtnSusbcribe(JButton btnSusbcribe) {
		this.btnSusbcribe = btnSusbcribe;
	}
	@Override
	public void update(Observable o, Object arg) {
		Message tempMsg = (Message)arg; 
		Subscriber s = (Subscriber) tempMsg.getObj();

		switch(tempMsg.getMsg())
		 {
		 	case "AddRegularSubscriber":
				if(tempMsg.isStatus())
				{
					JOptionPane.showMessageDialog(null , "Your Subscription Has Been Created , ID "+ Integer.toString(s.getSubID()));
				}	
				else
				{
					JOptionPane.showMessageDialog(null,"Subscription has failed,Try Again Later..: " + tempMsg.getStatusMsg(),"DATABASE ERROR",JOptionPane.ERROR_MESSAGE);
				}
				break;
		 }
		
	}
}
